﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using HMIS.MVC.CommonSupport.Filter;
using System.Drawing;
using System.Drawing.Imaging;

namespace HMIS.MVC.CommonSupport
{
	// 所有Controller都要继承的基类
	[AuthorizeFilter]
	[ExceFilter]
	public class BaseController : Controller
	{
		protected static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

		protected void GetQrCode(string encodeString, string psize)
		{
			int size = Int32.Parse(string.IsNullOrEmpty(psize) ? "120" : psize);
			com.google.zxing.qrcode.QRCodeWriter qrCode = new com.google.zxing.qrcode.QRCodeWriter();
			com.google.zxing.common.ByteMatrix byteIMG = qrCode.encode(encodeString, com.google.zxing.BarcodeFormat.QR_CODE, size, size);

			sbyte[][] img = byteIMG.Array;
			Bitmap bmp = new Bitmap(size, size);
			Graphics g = Graphics.FromImage(bmp);
			g.Clear(Color.White);

			for (int i = 0; i <= img.Length - 1; i++)
			{
				for (int j = 0; j <= img[i].Length - 1; j++)
				{
					if (img[j][i] == 0)
					{
						g.FillRectangle(Brushes.Black, i, j, 1, 1);
					}
					else
					{
						g.FillRectangle(Brushes.White, i, j, 1, 1);
					}
				}
			}
			bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
		} 
	}
}
